package com.iwhalecloud.bss.kite.cucc.web.controller.pay;

import com.iwhalecloud.bss.kite.client.dto.DataResult;
import com.iwhalecloud.bss.kite.common.constant.ErrorConsts;
import com.iwhalecloud.bss.kite.cucc.client.api.pay.IPaymentService;
import com.iwhalecloud.bss.kite.cucc.client.dto.order.OrderInfo;
import com.iwhalecloud.bss.kite.cucc.client.dto.pay.PayContentRspDTO;
import com.iwhalecloud.bss.kite.cucc.client.dto.pay.PayInfoConfirmDTO;
import com.iwhalecloud.bss.kite.cucc.client.dto.pay.PayStatusRspDTO;
import com.iwhalecloud.bss.kite.manager.transaction.KiteTransactional;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/pay")
@Api(tags = { "/pay - 支付" })
public class PaymentController {
    @Autowired
    private IPaymentService paymentService;

    @KiteTransactional
    @ApiOperation(value = "支付下单", notes = "支付下单")
    @ApiImplicitParams(
        @ApiImplicitParam(name = "orderInfo", value = "订单信息", required = true)
    )
    @PostMapping("/payOrder")
    public DataResult<PayContentRspDTO> payOrder(@RequestBody OrderInfo orderInfo) {
        return ErrorConsts.SUCCESS.getResult(paymentService.payOrder(orderInfo));
    }

    @KiteTransactional
    @ApiOperation(value = "支付状态结果查询", notes = "支付状态结果查询")
    @ApiImplicitParams(
        @ApiImplicitParam(name = "orderId", value = "订单号", required = true)
    )
    @GetMapping("/qryPayStatus")
    public DataResult<PayStatusRspDTO> qryPayStatus(@RequestParam(required = true) String orderId) {
        return ErrorConsts.SUCCESS.getResult(paymentService.qryPayStatus(orderId));
    }

    @KiteTransactional
    @ApiOperation(value = "缴费信息确认", notes = "缴费信息确认")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "orderId", value = "订单ID", required = true)
    })
    @GetMapping("/payInfoConfirm")
    public DataResult<PayInfoConfirmDTO> payInfoConfirm(@RequestParam(required = true) String orderId) {
        return ErrorConsts.SUCCESS.getResult(paymentService.payInfoConfirm(orderId));
    }
}
